package cn.dengta.webapp.user.model;

import java.util.*;
import java.util.stream.Collectors;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import cn.dengta.common.util.Common;
import lombok.Getter;
import me.codeplayer.util.CollectionUtil;
import me.codeplayer.util.X;

/**
 * 专题种类
 */
@Getter
public enum LinkCategory implements ValueProxyImpl<LinkCategory, Integer> {
	/** 首页 */
	TOP(0, "首页", true),
	/** 动态 */
	MOMENT(1, "动态", true),
	/** 消息 */
	IM_MSG(2, "消息", true),
	/** 钱包 */
	CASH(3, "钱包", true),
	/** 充值 */
	RECHARGE(4, "充值", false),
	/** 悬浮窗 */
	HAND(5, "悬浮窗", true),
	/** 用户中心 */
	USER_CENTER(6, "用户中心", false),
	/** 广告 */
	AD(7, "广告", true),
	/** 弹窗 */
	POPUP(8, "弹窗", true),
	TASK(8, "任务中心", true),
	//
	;

	// 定义私有变量
	public final Integer value;
	public final boolean show;
	final ValueProxy<LinkCategory, Integer> proxy;

	// 构造函数，枚举类型只能为私有
	LinkCategory(Integer value, String label, boolean show) {
		this.value = value;
		this.show = show;
		this.proxy = new ValueProxy<>(this, ordinal(), label);
	}

	public static final LinkCategory[] getValues() {
		return ValueProxy.getCachedArray(LinkCategory.class, LinkCategory::values);
	}

	public static LinkCategory of(Integer value) {
		return TOP.getValueOf(value);
	}

	public static List<LinkCategory> subtype;

	public static List<LinkCategory> subtype() {
		List<LinkCategory> types = subtype;
		if (!X.isValid(types)) {
			types = Arrays.stream(getValues()).filter(LinkCategory::isShow).collect(Collectors.toList());
			Common.replaceListValues(types, type -> {
				final Map<String, Object> map = CollectionUtil.ofHashMap("value", type.getValue(), "label", type.getLabel());
				X.use(LinkType.find(type), c -> map.put("subtype", c));
				return map;
			});
			subtype = types;
		}
		return types;
	}

}
